/*
 * ER/Studio 8.0 SQL Code Generation
 * Company :      ShiLu
 * Project :      Model1.DM1
 * Author :       JCC
 *
 * Date Created : Wednesday, September 02, 2020 15:51:14
 * Target DBMS : Microsoft SQL Server 2008
 */

/* 
 * TABLE: Hd_EquipmentHistory 
 */

CREATE TABLE Hd_EquipmentHistory(
    Id             bigint              IDENTITY(1,1),
    DevId          varchar(255)        NOT NULL,
    TagName        varchar(255)        NOT NULL,
    Name           varchar(255)        NULL,
    EquipmentId    uniqueidentifier    NULL,
    Value          varchar(255)        NULL,
    Value1         varchar(255)        NULL,
    CreateTime     datetime            NULL,
    Ticks          bigint              NULL,
    CONSTRAINT PK5 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Hd_EquipmentHistory') IS NOT NULL
    PRINT '<<< CREATED TABLE Hd_EquipmentHistory >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Hd_EquipmentHistory >>>'
go

/* 
 * TABLE: Hd_RiverHistory 
 */

CREATE TABLE Hd_RiverHistory(
    Id            bigint          IDENTITY(1,1),
    RiverCode     varchar(255)    NULL,
    RiverName     varchar(255)    NULL,
    Operator      varchar(255)    NULL,
    PH            varchar(255)    NULL,
    O2            varchar(255)    NULL,
    KMnO4         varchar(255)    NULL,
    NH3           varchar(255)    NULL,
    P             varchar(255)    NULL,
    CreateTime    datetime        NULL,
    CONSTRAINT PK7 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Hd_RiverHistory') IS NOT NULL
    PRINT '<<< CREATED TABLE Hd_RiverHistory >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Hd_RiverHistory >>>'
go

/* 
 * TABLE: Md_Equipment 
 */

CREATE TABLE Md_Equipment(
    Id               uniqueidentifier    NOT NULL,
    DevId            varchar(255)        NULL,
    ProjectId        varchar(255)        NULL,
    Name             varchar(255)        NULL,
    Status           varchar(255)        NULL,
    MachineType      varchar(255)        NULL,
    Location         varchar(255)        NULL,
    X                float               NULL,
    Y                float               NULL,
    SN               varchar(255)        NULL,
    PN               varchar(255)        NULL,
    Specification    varchar(255)        NULL,
    Origin           varchar(255)        NULL,
    Supplier         varchar(255)        NULL,
    SupplyTime       datetime            NULL,
    Description      varchar(500)        NULL,
    CreateTime       datetime            NULL,
    Url              varchar(1000)       NULL,
    Token            varchar(500)        NULL,
    Maintenance      varchar(255)        NULL,
    Operator         varchar(255)        NULL,
    ContractWay      varchar(255)        NULL,
    ImageUrl         varchar(255)        NULL,
    SectionId        uniqueidentifier    NULL,
    CONSTRAINT PK2 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Md_Equipment') IS NOT NULL
    PRINT '<<< CREATED TABLE Md_Equipment >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Md_Equipment >>>'
go

/* 
 * TABLE: Md_EquipmentSass 
 */

CREATE TABLE Md_EquipmentSass(
    Id             bigint              IDENTITY(1,1),
    SassId         uniqueidentifier    NOT NULL,
    EquipmentId    uniqueidentifier    NOT NULL,
    CONSTRAINT PK8 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Md_EquipmentSass') IS NOT NULL
    PRINT '<<< CREATED TABLE Md_EquipmentSass >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Md_EquipmentSass >>>'
go

/* 
 * TABLE: Md_Section 
 */

CREATE TABLE Md_Section(
    Id            uniqueidentifier    NOT NULL,
    ParentId      uniqueidentifier    NULL,
    Name          varchar(255)        NULL,
    Level         int                 NULL,
    CreateTime    datetime            NULL,
    X             float               NULL,
    Y             float               NULL,
    CONSTRAINT PK1 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Md_Section') IS NOT NULL
    PRINT '<<< CREATED TABLE Md_Section >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Md_Section >>>'
go

/* 
 * TABLE: Sys_Menu 
 */

CREATE TABLE Sys_Menu(
    Id             uniqueidentifier    NOT NULL,
    Name           varchar(255)        NULL,
    Path           varchar(255)        NULL,
    Icon           varchar(255)        NULL,
    Status         varchar(255)        NULL,
    Description    varchar(500)        NULL,
    CreateTime     datetime            NULL,
    CONSTRAINT PK11 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Sys_Menu') IS NOT NULL
    PRINT '<<< CREATED TABLE Sys_Menu >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Sys_Menu >>>'
go

/* 
 * TABLE: Sys_Role 
 */

CREATE TABLE Sys_Role(
    Id             uniqueidentifier    NOT NULL,
    Name           varchar(255)        NULL,
    Status         varchar(255)        NULL,
    CreateTime     datetime            NULL,
    Description    varchar(500)        NULL,
    SassId         uniqueidentifier    NULL,
    CONSTRAINT PK9 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Sys_Role') IS NOT NULL
    PRINT '<<< CREATED TABLE Sys_Role >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Sys_Role >>>'
go

/* 
 * TABLE: Sys_RoleMenu 
 */

CREATE TABLE Sys_RoleMenu(
    Id_1    bigint              IDENTITY(1,1),
    RId     uniqueidentifier    NULL,
    MId     uniqueidentifier    NULL,
    CONSTRAINT PK12 PRIMARY KEY NONCLUSTERED (Id_1)
)
go



IF OBJECT_ID('Sys_RoleMenu') IS NOT NULL
    PRINT '<<< CREATED TABLE Sys_RoleMenu >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Sys_RoleMenu >>>'
go

/* 
 * TABLE: Sys_Sass 
 */

CREATE TABLE Sys_Sass(
    Id               uniqueidentifier    NOT NULL,
    Name             varchar(255)        NULL,
    UserName         varchar(255)        NULL,
    Password         varchar(255)        NULL,
    Mobile           varchar(255)        NULL,
    Email            varchar(255)        NULL,
    Des              varchar(255)        NULL,
    AllowUsers       int                 NULL,
    AllowMachines    int                 NULL,
    CreateTime       datetime            NULL,
    Description      varchar(500)        NULL,
    Status           varchar(255)        NULL,
    DB               varchar(255)        NULL,
    CompanyName      varchar(255)        NULL,
    TaxNum           varchar(255)        NULL,
    Contact          varchar(255)        NULL,
    Bank             varchar(255)        NULL,
    BankNum          varchar(255)        NULL,
    Remark           varchar(255)        NULL,
    Expire           datetime            NULL,
    CONSTRAINT PK4 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Sys_Sass') IS NOT NULL
    PRINT '<<< CREATED TABLE Sys_Sass >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Sys_Sass >>>'
go

/* 
 * TABLE: Sys_User 
 */

CREATE TABLE Sys_User(
    Id             uniqueidentifier    NOT NULL,
    Name           varchar(255)        NULL,
    UserName       varchar(255)        NULL,
    Password       varchar(255)        NULL,
    Email          varchar(255)        NULL,
    Mobile         varchar(255)        NULL,
    CreateTime     datetime            NULL,
    Description    varchar(500)        NULL,
    Status         varchar(255)        NULL,
    SassId         uniqueidentifier    NULL,
    CONSTRAINT PK6 PRIMARY KEY NONCLUSTERED (Id)
)
go



IF OBJECT_ID('Sys_User') IS NOT NULL
    PRINT '<<< CREATED TABLE Sys_User >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Sys_User >>>'
go

/* 
 * TABLE: Sys_UserRole 
 */

CREATE TABLE Sys_UserRole(
    UserId    bigint              IDENTITY(1,1),
    UId       uniqueidentifier    NULL,
    RId       uniqueidentifier    NULL,
    CONSTRAINT PK10 PRIMARY KEY NONCLUSTERED (UserId)
)
go



IF OBJECT_ID('Sys_UserRole') IS NOT NULL
    PRINT '<<< CREATED TABLE Sys_UserRole >>>'
ELSE
    PRINT '<<< FAILED CREATING TABLE Sys_UserRole >>>'
go

/* 
 * TABLE: Md_Equipment 
 */

ALTER TABLE Md_Equipment ADD CONSTRAINT RefMd_Section2 
    FOREIGN KEY (SectionId)
    REFERENCES Md_Section(Id)
go


/* 
 * TABLE: Sys_Role 
 */

ALTER TABLE Sys_Role ADD CONSTRAINT RefSys_Sass4 
    FOREIGN KEY (SassId)
    REFERENCES Sys_Sass(Id)
go


/* 
 * TABLE: Sys_RoleMenu 
 */

ALTER TABLE Sys_RoleMenu ADD CONSTRAINT RefSys_Menu10 
    FOREIGN KEY (MId)
    REFERENCES Sys_Menu(Id)
go

ALTER TABLE Sys_RoleMenu ADD CONSTRAINT RefSys_Role11 
    FOREIGN KEY (RId)
    REFERENCES Sys_Role(Id)
go


/* 
 * TABLE: Sys_User 
 */

ALTER TABLE Sys_User ADD CONSTRAINT RefSys_Sass3 
    FOREIGN KEY (SassId)
    REFERENCES Sys_Sass(Id)
go


/* 
 * TABLE: Sys_UserRole 
 */

ALTER TABLE Sys_UserRole ADD CONSTRAINT RefSys_User8 
    FOREIGN KEY (UId)
    REFERENCES Sys_User(Id)
go

ALTER TABLE Sys_UserRole ADD CONSTRAINT RefSys_Role9 
    FOREIGN KEY (RId)
    REFERENCES Sys_Role(Id)
go


